home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
This Disc Bytes!
/
Power Computing - The Disc 2 - This Disc Bytes.ISO
/
mac
/
CodeWarrior 7 Lite for 68K
/
MacOS Examples
/
MW AboutBox
/
About.c
next >
Wrap
Text File
|
1995-12-05
|
27KB
|
907 lines
/************************************************************************/
/* Project...: C++ and ANSI-C Compiler Environment */
/* Name......: MWAbout.c */
/* Purpose...: about box */
/* Copyright.: ©Copyright 1993 by metrowerks inc. All rights reserved. */
/************************************************************************/
/* CodeWarrior Lite
* January 1996
* © 1996 Metrowerks, Corp.
*/
enum {
ditl_about = 607, // about DITL
ditl_about_items = 8, // number of items in DITL
ditl_about_background = 1, // background about item
ditl_about_bigbar, // big tracking bar
ditl_about_smallbar, // small tracking bar
ditl_about_logobox, // company logo
ditl_about_namebox, // company name
ditl_about_creditsbox, // credits
ditl_about_bigbarshadow, // big bar shadow
ditl_about_smallbarshadow, // smallbar shadow
ditl_about_versionbox, // version number +GHD
ditl_about_helpitem // hook for ballon help
};
#include <GestaltEqu.h>
#include <QDOffscreen.h>
#include <Sound.h>
#define TEXT_AboutVersion 607
#define TEXT_Credits 1000
#define WIND_MetroAbout 1000
#define PICT_Background 1000
#define PICT_BigBar 1001
#define PICT_BigBarShadow 2001
#define PICT_SmallBar 1002
#define PICT_SmallBarShadow 2002
#define PICT_LogoBox 3001
#define PICT_LogoHalf 3002
#define PICT_LogoWhole 3003
#define PICT_NameBox 3004
#define snd_NameBoxClank 3004
#define Bounce_Distance 10
#define Fade_Levels 12
typedef struct UserItemRec {
long padding1;
Rect box;
short padding2;
} UserItemRec;
typedef struct DITLRec {
short numItems;
UserItemRec theUserItems[1];
} DITLRec, **DITLHand;
void DoAboutBox(Boolean simpleAbout);
void DoSimpleAbout(void);
void SetUpGraphics(void);
void DoAnimation(void);
void CleanUpGraphics(void);
void GetItemRect(short inItem, Rect *outRect);
void DrawPictIntoNewGWorld(short inPICTid, short inDepth,
GWorldPtr *outGWorldP);
void DrawTextIntoNewGWorld(short inTEXTid, Rect *inBounds, short inDepth,
GWorldPtr *outGWorldP);
typedef enum AnimateState {
animate_Waiting,
animate_Active,
animate_Done
} AnimateState;
void MoveOffWorld(GWorldPtr theGWorldP, Rect *currPos, Rect *newPos,
Rect *imagePos);
void MoveBar(GWorldPtr theGWorldP, GWorldPtr theShadowWorldP, Rect *inCurrPos,
Rect *inShadowPos, short inHorizOffset);
void MoveLogoBox(GWorldPtr theGWorldP, Rect *inCurrPos, short inVertOffset);
typedef struct BarRec {
GWorldPtr theGWorldP;
GWorldPtr theShadowWorldP;
Rect currPos;
Rect shadowPos;
} BarRec;
void SetUpBigBar(BarRec *inBigBarRec);
void SetUpSmallBar(BarRec *inSmallBarRec);
typedef struct LogoRec {
GWorldPtr theGWorldP;
Rect currPos;
Rect imagePos;
short bottomLoc;
} LogoRec;
void SetUpLogoBox(LogoRec *inLogoBoxRec);
void SetUpNameBox(LogoRec *inNameBoxRec);
typedef struct CreditsRec {
GWorldPtr theGWorldP;
Rect viewRect;
Rect pictRect;
short pictHeight;
} CreditsRec;
void SetUpCredits(CreditsRec *inCreditsRec);
static short Pixel_Depth;
static CWindowPtr aboutBoxWindow;
static PixMapPtr windowPixMapP;
static GWorldPtr drawWorldP;
static PixMapPtr drawPixMapP;
static GWorldPtr backWorldP;
static PixMapPtr backPixMapP;
void DoAboutBox(Boolean simpleAbout)
{
long qdVersion;
GWorldPtr saveWorld;
GDHandle saveDevice;
Gestalt(gestaltQuickdrawVersion, &qdVersion);
if (simpleAbout || (qdVersion < gestalt32BitQD) || (FreeMem() < 350000)) {
GrafPtr savePort;
// Machine lacks 32bit QuickDraw or there's not enough memory.
GetPort(&savePort);
DoSimpleAbout();
SetPort(savePort);
} else { // OK to do animated about box.
GetGWorld(&saveWorld, &saveDevice);
SetUpGraphics();
DoAnimation();
CleanUpGraphics();
PurgeMem(maxSize);
SetGWorld(saveWorld, saveDevice);
}
}
static void DoSimpleAbout(void)
{
WindowPtr macWindow = GetNewWindow(WIND_MetroAbout, nil, (WindowPtr) -1L);
PicHandle thePicture;
Handle theText;
Rect r;
long ticks;
ShowWindow(macWindow);
SetPort(macWindow);
thePicture = GetPicture(PICT_Background);
if (thePicture != nil) {
r = (**thePicture).picFrame;
DrawPicture(thePicture, &r);
ReleaseResource((Handle)thePicture);
GetItemRect(ditl_about_versionbox, &r);
theText = GetResource('TEXT', TEXT_AboutVersion);
HLock(theText);
TextSize(9);
TextFace(bold);
TextBox(*theText, GetHandleSize(theText), &r, teJustRight);
ReleaseResource(theText);
Delay(45, &ticks);
thePicture = GetPicture(PICT_LogoWhole);
GetItemRect(ditl_about_logobox, &r);
DrawPicture(thePicture, &r);
ReleaseResource((Handle)thePicture);
Delay(45, &ticks);
thePicture = GetPicture(PICT_NameBox);
GetItemRect(ditl_about_namebox, &r);
DrawPicture(thePicture, &r);
ReleaseResource((Handle)thePicture);
Delay(45, &ticks);
while (!Button())
;
}
DisposeWindow(macWindow);
}
static void SetUpGraphics(void)
{
Rect backRect;
PixMapHandle thePixMapH;
Rect versionOffBox, versionWindowBox;
GWorldPtr versionWorld;
Pixel_Depth = 8;
// Make GWorld for offscreen drawing.
GetItemRect(ditl_about_background, &backRect);
NewGWorld(&drawWorldP, Pixel_Depth, &backRect, nil, nil, 0);
thePixMapH = GetGWorldPixMap(drawWorldP);
HLockHi((Handle)thePixMapH);
LockPixels(thePixMapH);
drawPixMapP = *thePixMapH;
// Make GWorld for background.
DrawPictIntoNewGWorld(PICT_Background, Pixel_Depth, &backWorldP);
thePixMapH = GetGWorldPixMap(backWorldP);
HLockHi((Handle)thePixMapH);
LockPixels(thePixMapH);
backPixMapP = *thePixMapH;
// Make Window.
aboutBoxWindow = (CWindowPtr) GetNewCWindow(WIND_MetroAbout, nil,
(WindowPtr) - 1L);
ShowWindow((WindowPtr)aboutBoxWindow);
HLockHi((Handle)aboutBoxWindow->portPixMap);
windowPixMapP = *aboutBoxWindow->portPixMap;
// Draw background in Window.
SetGWorld(aboutBoxWindow, GetMainDevice());
CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &backRect,
&backRect, srcCopy, nil);
// Draw Version Number +GHD
GetItemRect(ditl_about_versionbox, &versionWindowBox);
versionOffBox = versionWindowBox;
DrawTextIntoNewGWorld(TEXT_AboutVersion, &versionOffBox, Pixel_Depth, &versionWorld);
LockPixels(GetGWorldPixMap(versionWorld));
versionWindowBox.bottom = versionWindowBox.top + versionOffBox.bottom;
CopyBits((BitMapPtr)*GetGWorldPixMap(versionWorld), (BitMapPtr)windowPixMapP, &versionOffBox,
&versionWindowBox, adMax, nil);
DisposeGWorld(versionWorld);
}
void SetUpBigBar(BarRec *inBigBarRec)
{
DrawPictIntoNewGWorld(PICT_BigBar, Pixel_Depth, &inBigBarRec->theGWorldP);
DrawPictIntoNewGWorld(PICT_BigBarShadow, Pixel_Depth,
&inBigBarRec->theShadowWorldP);
GetItemRect(ditl_about_bigbar, &inBigBarRec->currPos);
GetItemRect(ditl_about_bigbarshadow, &inBigBarRec->shadowPos);
OffsetRect(&inBigBarRec->currPos, -inBigBarRec->shadowPos.right, 0);
OffsetRect(&inBigBarRec->shadowPos, -inBigBarRec->shadowPos.right, 0);
}
void SetUpSmallBar(BarRec *inSmallBarRec)
{
short barWidth;
DrawPictIntoNewGWorld(PICT_SmallBar, Pixel_Depth,
&inSmallBarRec->theGWorldP);
DrawPictIntoNewGWorld(PICT_SmallBarShadow, Pixel_Depth,
&inSmallBarRec->theShadowWorldP);
GetItemRect(ditl_about_smallbar, &inSmallBarRec->currPos);
GetItemRect(ditl_about_smallbarshadow, &inSmallBarRec->shadowPos);
barWidth = inSmallBarRec->currPos.right - inSmallBarRec->currPos.left;
inSmallBarRec->currPos.left = inSmallBarRec->currPos.right;
inSmallBarRec->currPos.right += barWidth;
OffsetRect(&inSmallBarRec->shadowPos, barWidth, 0);
}
void SetUpLogoBox(LogoRec *inLogoBoxRec)
{
GetItemRect(ditl_about_logobox, &inLogoBoxRec->currPos);
inLogoBoxRec->bottomLoc = inLogoBoxRec->currPos.bottom;
OffsetRect(&inLogoBoxRec->currPos, 0, -inLogoBoxRec->currPos.bottom);
}
void SetUpNameBox(LogoRec *inNameBoxRec)
{
DrawPictIntoNewGWorld(PICT_NameBox, Pixel_Depth,
&inNameBoxRec->theGWorldP);
GetItemRect(ditl_about_namebox, &inNameBoxRec->currPos);
inNameBoxRec->bottomLoc = inNameBoxRec->currPos.bottom;
OffsetRect(&inNameBoxRec->currPos, 0, -inNameBoxRec->currPos.bottom);
inNameBoxRec->imagePos.left = inNameBoxRec->imagePos.top = 0;
inNameBoxRec->imagePos.right = inNameBoxRec->currPos.right -
inNameBoxRec->currPos.left;
inNameBoxRec->imagePos.bottom = inNameBoxRec->currPos.bottom -
inNameBoxRec->currPos.top;
}
void SetUpCredits(CreditsRec *inCreditsRec)
{
PicHandle pictureH;
Rect picFrame;
PixMapHandle thePixMapH;
Rect creditsBox;
// The only animation is the credits
// Therefore, we can reduce the size of the offscreen worlds for the background
// and scratch drawing to just cover the area where the credits are drawn.
DisposeGWorld(backWorldP);
DisposeGWorld(drawWorldP);
GetItemRect(ditl_about_creditsbox, &inCreditsRec->viewRect);
// Make GWorld for offscreen drawing.
NewGWorld(&drawWorldP, Pixel_Depth, &inCreditsRec->viewRect, nil, nil, 0);
thePixMapH = GetGWorldPixMap(drawWorldP);
HLockHi((Handle)thePixMapH);
LockPixels(thePixMapH);
drawPixMapP = *thePixMapH;
// Make GWorld for background.
NewGWorld(&backWorldP, Pixel_Depth, &inCreditsRec->viewRect, nil,
GetGWorldDevice(drawWorldP), noNewDevice);
thePixMapH = GetGWorldPixMap(backWorldP);
HLockHi((Handle)thePixMapH);
LockPixels(thePixMapH);
backPixMapP = *thePixMapH;
SetGWorld(backWorldP, nil);
pictureH = GetPicture(PICT_Background);
picFrame = (**pictureH).picFrame;
DrawPicture(pictureH, &picFrame);
ReleaseResource((Handle)pictureH);
// Make GWorld for credits.
creditsBox = inCreditsRec->viewRect;
DrawTextIntoNewGWorld(TEXT_Credits, &creditsBox,
Pixel_Depth, &inCreditsRec->theGWorldP);
inCreditsRec->pictRect.left = 0;
inCreditsRec->pictRect.top = 0;
inCreditsRec->pictRect.right = inCreditsRec->viewRect.right -
inCreditsRec->viewRect.left;
inCreditsRec->pictRect.bottom = inCreditsRec->viewRect.bottom -
inCreditsRec->viewRect.top;
inCreditsRec->pictHeight = creditsBox.bottom;
}
void MoveBar(GWorldPtr theGWorldP, GWorldPtr theShadowWorldP, Rect *inCurrPos,
Rect *inShadowPos, short inHorizOffset)
{
Rect exposedRect, coveredRect, imageRect;
Rect shadowFront, shadowBack;
PixMapHandle offPixMapH;
// Draw to the Window.
SetGWorld(aboutBoxWindow, GetMainDevice());
// Determine areas exposed and covered by bar as it moves.
exposedRect = coveredRect = *inCurrPos;
shadowFront = shadowBack = *inShadowPos;
if (inHorizOffset > 0) {
exposedRect.right = exposedRect.left + inHorizOffset;
coveredRect.left = coveredRect.right;
coveredRect.right += inHorizOffset;
shadowBack.right = shadowBack.left + inHorizOffset;
shadowBack.top = coveredRect.bottom;
shadowFront.left = shadowFront.right;
shadowFront.right += inHorizOffset;
} else {
exposedRect.left = exposedRect.right + inHorizOffset;
exposedRect.bottom = shadowBack.top;
coveredRect.right = coveredRect.left;
coveredRect.left += inHorizOffset;
shadowBack.left = shadowBack.right + inHorizOffset;
shadowFront.right = shadowFront.left;
shadowFront.left += inHorizOffset;
shadowFront.top = coveredRect.bottom;
}
imageRect.left = coveredRect.left;
imageRect.right = coveredRect.right;
imageRect.top = 0;
imageRect.bottom = coveredRect.bottom - coveredRect.top;
// Restore background over exposed area.
CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &exposedRect,
&exposedRect, srcCopy, nil);
CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &shadowBack,
&shadowBack, srcCopy, nil);
// Draw image at covered area.
offPixMapH = GetGWorldPixMap(theGWorldP);
LockPixels(offPixMapH);
CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP, &imageRect,
&coveredRect, srcCopy, nil);
UnlockPixels(offPixMapH);
offPixMapH = GetGWorldPixMap(theShadowWorldP);
LockPixels(offPixMapH);
CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP, &shadowFront,
&shadowFront, srcCopy, nil);
if (inHorizOffset < 0) {
shadowFront.left = exposedRect.left;
shadowFront.right = exposedRect.right;
shadowFront.top = shadowBack.top;
CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP,
&shadowFront, &shadowFront, srcCopy, nil);
}
UnlockPixels(offPixMapH);
}
void MoveLogoBox(GWorldPtr theGWorldP, Rect *inCurrPos, short inVertOffset)
{
Rect exposedRect, coveredRect, imageRect;
RGBColor boxColor = {
65535, 52428, 0
};
// Draw to the Window.
SetGWorld(aboutBoxWindow, GetMainDevice());
// Determine areas exposed and covered by bar as it moves.
exposedRect = coveredRect = *inCurrPos;
if (inVertOffset > 0) {
exposedRect.bottom = exposedRect.top + inVertOffset;
coveredRect.top = coveredRect.bottom;
coveredRect.bottom += inVertOffset;
} else {
exposedRect.top = exposedRect.bottom + inVertOffset;
coveredRect.bottom = coveredRect.top;
coveredRect.top += inVertOffset;
}
imageRect.left = 0;
imageRect.right = coveredRect.right - coveredRect.left;
imageRect.top = 0;
imageRect.bottom = coveredRect.bottom - coveredRect.top;
// Restore background over exposed area.
CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &exposedRect,
&exposedRect, srcCopy, nil);
// Draw image at covered area.
RGBForeColor(&boxColor);
PaintRect(&coveredRect);
ForeColor(blackColor);
}
void MoveOffWorld(GWorldPtr theGWorldP, Rect *inCurrPos, Rect *inNewPos,
Rect *inOffPos)
{
Rect drawRect;
PixMapHandle offPixMapH;
// Create image in draw world.
SetGWorld(drawWorldP, nil);
// Restore background at current position.
CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP, inCurrPos,
inCurrPos, srcCopy, nil);
// Draw image at new position.
offPixMapH = GetGWorldPixMap(theGWorldP);
LockPixels(offPixMapH);
CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)drawPixMapP, inOffPos,
inNewPos, srcCopy, nil);
UnlockPixels(offPixMapH);
// Draw union of old and new position to Window.
SetGWorld(aboutBoxWindow, GetMainDevice());
UnionRect(inCurrPos, inNewPos, &drawRect);
CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP, &drawRect,
&drawRect, srcCopy, nil);
}
static void DoAnimation(void)
{
BarRec theBigBarRec;
BarRec theSmallBarRec;
LogoRec theLogoBoxRec;
LogoRec theNameBoxRec;
CreditsRec theCreditsRec;
Rect currPos, imagePos;
PicHandle thePictureH;
SndChannelPtr theSoundChannelP = nil;
Handle theSoundH = nil;
AnimateState animBigBar = animate_Active;
AnimateState animSmallBar = animate_Waiting;
AnimateState animLogoBoxDown = animate_Waiting;
AnimateState animLogoBoxUp = animate_Waiting;
AnimateState animNameBoxDown = animate_Waiting;
AnimateState animNameBoxUp = animate_Waiting;
AnimateState animCreditsFade = animate_Waiting;
AnimateState animCreditsScroll = animate_Waiting;
Boolean logoHalfDrawn = false;
Boolean logoWholeDrawn = false;
RGBColor fadeColor;
short grayIndex = 0;
unsigned short grayLevels[Fade_Levels] = {
4369, 8738, 17476, 21845, 30583, 34952, 43690, 48059, 52428, 56979,
61166, 65535
};
theBigBarRec.theGWorldP = nil;
theBigBarRec.theShadowWorldP = nil;
theSmallBarRec.theGWorldP = nil;
theSmallBarRec.theShadowWorldP = nil;
theLogoBoxRec.theGWorldP = nil;
theNameBoxRec.theGWorldP = nil;
theCreditsRec.theGWorldP = nil;
SetUpBigBar(&theBigBarRec);
SetUpLogoBox(&theLogoBoxRec);
theSoundH = GetResource('snd ', snd_NameBoxClank);
theSmallBarRec.currPos.left = 1000;
while (!Button()) {
long ticks;
long endTicks;
long startTicks = TickCount();
if ((animLogoBoxDown == animate_Waiting) &&
(theBigBarRec.currPos.left > 100)) {
animLogoBoxDown = animate_Active;
}
if ((animLogoBoxDown == animate_Active) &&
(theLogoBoxRec.currPos.bottom >=
theLogoBoxRec.bottomLoc + Bounce_Distance)) {
animLogoBoxDown = animate_Done;
animLogoBoxUp = animate_Active;
}
if ((animLogoBoxUp == animate_Active) &&
(theLogoBoxRec.currPos.bottom <= theLogoBoxRec.bottomLoc)) {
animLogoBoxUp = animate_Done;
}
if ((animBigBar == animate_Active) && !logoHalfDrawn &&
(theBigBarRec.currPos.right > theLogoBoxRec.currPos.right)) {
SetGWorld(backWorldP, nil);
thePictureH = GetPicture(PICT_LogoHalf);
DrawPicture(thePictureH, &theLogoBoxRec.currPos);
ReleaseResource((Handle)thePictureH);
logoHalfDrawn = true;
}
if ((animBigBar == animate_Active) &&
theBigBarRec.currPos.left > backWorldP->portRect.right) {
animBigBar = animate_Done;
DisposeGWorld(theBigBarRec.theGWorldP);
theBigBarRec.theGWorldP = nil;
DisposeGWorld(theBigBarRec.theShadowWorldP);
theBigBarRec.theShadowWorldP = nil;
animSmallBar = animate_Active;
SetUpSmallBar(&theSmallBarRec);
}
if ((animSmallBar == animate_Active) && !logoWholeDrawn &&
(theSmallBarRec.currPos.left < theLogoBoxRec.currPos.left)) {
SetGWorld(backWorldP, nil);
thePictureH = GetPicture(PICT_LogoWhole);
DrawPicture(thePictureH, &theLogoBoxRec.currPos);
ReleaseResource((Handle)thePictureH);
logoWholeDrawn = true;
}
if ((animNameBoxDown == animate_Waiting) &&
(theSmallBarRec.currPos.left < 150)) {
animNameBoxDown = animate_Active;
SetUpNameBox(&theNameBoxRec);
}
if ((animNameBoxDown == animate_Active) &&
(theNameBoxRec.currPos.bottom >=
theNameBoxRec.bottomLoc + Bounce_Distance)) {
animNameBoxDown = animate_Done;
animNameBoxUp = animate_Active;
}
if ((animNameBoxUp == animate_Active) &&
(theNameBoxRec.currPos.bottom <= theNameBoxRec.bottomLoc)) {
OSErr err;
animNameBoxUp = animate_Done;
DisposeGWorld(theNameBoxRec.theGWorldP);
theNameBoxRec.theGWorldP = nil;
if (theSoundH != nil) {
err = SndNewChannel(&theSoundChannelP, sampledSynth, initMono,
nil);
if (err == noErr)
SndPlay(theSoundChannelP, (SndListHandle)theSoundH, true);
}
}
if ((animSmallBar == animate_Active) &&
(theSmallBarRec.shadowPos.right < backWorldP->portRect.left)) {
animSmallBar = animate_Done;
DisposeGWorld(theSmallBarRec.theGWorldP);
theSmallBarRec.theGWorldP = nil;
DisposeGWorld(theSmallBarRec.theShadowWorldP);
theSmallBarRec.theShadowWorldP = nil;
if (theSoundChannelP != nil) {
SndDisposeChannel(theSoundChannelP, true);
theSoundChannelP = nil;
}
if (theSoundH != nil) {
ReleaseResource(theSoundH);
theSoundH = nil;
}
animCreditsFade = animate_Active;
SetUpCredits(&theCreditsRec);
}
if ((animCreditsFade == animate_Active) &&
(grayIndex >= Fade_Levels)) {
animCreditsFade = animate_Done;
Delay(90, &ticks);
animCreditsScroll = animate_Active;
}
if ((animCreditsScroll == animate_Active) &&
(theCreditsRec.pictRect.top > theCreditsRec.pictHeight)) {
theCreditsRec.pictRect.top = 1;
theCreditsRec.pictRect.bottom = theCreditsRec.viewRect.bottom -
theCreditsRec.viewRect.top + 1;
}
if (animBigBar == animate_Active) {
MoveBar(theBigBarRec.theGWorldP, theBigBarRec.theShadowWorldP,
&theBigBarRec.currPos, &theBigBarRec.shadowPos, 1);
theBigBarRec.currPos.left++;
theBigBarRec.currPos.right++;
theBigBarRec.shadowPos.left++;
theBigBarRec.shadowPos.right++;
}
if (animLogoBoxDown == animate_Active) {
MoveLogoBox(theLogoBoxRec.theGWorldP, &theLogoBoxRec.currPos, 1);
theLogoBoxRec.currPos.top++;
theLogoBoxRec.currPos.bottom++;
}
if (animLogoBoxUp == animate_Active) {
MoveLogoBox(theLogoBoxRec.theGWorldP, &theLogoBoxRec.currPos, -1);
theLogoBoxRec.currPos.top--;
theLogoBoxRec.currPos.bottom--;
}
if (animSmallBar == animate_Active) {
MoveBar(theSmallBarRec.theGWorldP, theSmallBarRec.theShadowWorldP,
&theSmallBarRec.currPos, &theSmallBarRec.shadowPos, -1);
theSmallBarRec.currPos.left--;
theSmallBarRec.currPos.right--;
theSmallBarRec.shadowPos.left--;
theSmallBarRec.shadowPos.right--;
}
if (animNameBoxDown == animate_Active) {
currPos = theNameBoxRec.currPos;
theNameBoxRec.currPos.top++;
theNameBoxRec.currPos.bottom++;
imagePos = theNameBoxRec.imagePos;
MoveOffWorld(theNameBoxRec.theGWorldP, &currPos,
&theNameBoxRec.currPos, &imagePos);
}
if (animNameBoxUp == animate_Active) {
currPos = theNameBoxRec.currPos;
theNameBoxRec.currPos.top--;
theNameBoxRec.currPos.bottom--;
imagePos = theNameBoxRec.imagePos;
MoveOffWorld(theNameBoxRec.theGWorldP, &currPos,
&theNameBoxRec.currPos, &imagePos);
}
if (animCreditsFade == animate_Active) {
PixMapHandle thePixMapH;
Delay(3, &ticks);
SetGWorld(drawWorldP, nil);
thePixMapH = GetGWorldPixMap(theCreditsRec.theGWorldP);
LockPixels(thePixMapH);
CopyBits((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP,
&theCreditsRec.pictRect, &theCreditsRec.viewRect,
srcCopy, nil);
UnlockPixels(thePixMapH);
fadeColor.red = fadeColor.blue = fadeColor.green =
grayLevels[grayIndex++];
RGBForeColor(&fadeColor);
PenMode(adMin);
PaintRect(&theCreditsRec.viewRect);
PenMode(patCopy);
ForeColor(blackColor);
CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP,
&theCreditsRec.viewRect, &theCreditsRec.viewRect, adMax,
nil);
SetGWorld(aboutBoxWindow, GetMainDevice());
CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP,
&theCreditsRec.viewRect, &theCreditsRec.viewRect,
srcCopy, nil);
}
if (animCreditsScroll == animate_Active) {
PixMapHandle thePixMapH;
short i, j;
short creditsWidth =
theCreditsRec.viewRect.right -theCreditsRec.viewRect.left -1;
Rect wrapViewRect, wrapPictRect;
SetGWorld(drawWorldP, nil);
theCreditsRec.pictRect.top += 1;
theCreditsRec.pictRect.bottom += 1;
thePixMapH = GetGWorldPixMap(theCreditsRec.theGWorldP);
LockPixels(thePixMapH);
if (theCreditsRec.pictRect.bottom <= theCreditsRec.pictHeight) {
CopyBits((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP,
&theCreditsRec.pictRect, &theCreditsRec.viewRect,
srcCopy, nil);
} else {
wrapViewRect = theCreditsRec.viewRect;
wrapViewRect.top = wrapViewRect.bottom -
(theCreditsRec.pictRect.bottom -
theCreditsRec.pictHeight);
wrapPictRect = theCreditsRec.pictRect;
wrapPictRect.top = 0;
wrapPictRect.bottom = wrapPictRect.top +
(wrapViewRect.bottom - wrapViewRect.top);
CopyBits((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP,
&theCreditsRec.pictRect, &theCreditsRec.viewRect,
srcCopy, nil);
CopyBits((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP,
&wrapPictRect, &wrapViewRect, srcCopy, nil);
}
UnlockPixels(thePixMapH);
PenMode(adMin); // Fade out at top and fade in at bottom
j = Fade_Levels - 1;
for (i = 0; i < j; i++) {
fadeColor.red = fadeColor.blue = fadeColor.green =
grayLevels[i];
RGBForeColor(&fadeColor);
MoveTo(theCreditsRec.viewRect.left,
theCreditsRec.viewRect.top + i);
Line(creditsWidth, 0);
MoveTo(theCreditsRec.viewRect.left,
theCreditsRec.viewRect.bottom - i - 1);
Line(creditsWidth, 0);
}
ForeColor(blackColor);
PenMode(patCopy);
CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP,
&theCreditsRec.viewRect, &theCreditsRec.viewRect, adMax,
nil);
SetGWorld(aboutBoxWindow, GetMainDevice());
CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP,
&theCreditsRec.viewRect, &theCreditsRec.viewRect,
srcCopy, nil);
}
endTicks = TickCount(); // Timing loop.
if (endTicks == startTicks) { // TickCount must change during each pass thru animation loop.
while (endTicks == TickCount())
; // this puts an upper speed limit on the animation rate.
}
}
// Finished animation (user clicked). Flush the mousedown events
FlushEvents(mDownMask | mUpMask | keyDownMask | keyUpMask | autoKeyMask,
0);
// Dispose of all GWorlds (if they haven't already been disposed).
if (theBigBarRec.theGWorldP != nil)
DisposeGWorld(theBigBarRec.theGWorldP);
if (theBigBarRec.theShadowWorldP != nil)
DisposeGWorld(theBigBarRec.theShadowWorldP);
if (theSmallBarRec.theGWorldP != nil)
DisposeGWorld(theSmallBarRec.theGWorldP);
if (theSmallBarRec.theShadowWorldP != nil)
DisposeGWorld(theSmallBarRec.theShadowWorldP);
if (theLogoBoxRec.theGWorldP != nil)
DisposeGWorld(theLogoBoxRec.theGWorldP);
if (theNameBoxRec.theGWorldP != nil)
DisposeGWorld(theNameBoxRec.theGWorldP);
if (theCreditsRec.theGWorldP != nil)
DisposeGWorld(theCreditsRec.theGWorldP);
if (theSoundChannelP != nil)
SndDisposeChannel(theSoundChannelP, true);
if (theSoundH != nil)
ReleaseResource(theSoundH);
}
static void CleanUpGraphics(void)
{
DisposeGWorld(drawWorldP);
DisposeGWorld(backWorldP);
DisposeWindow((WindowPtr)aboutBoxWindow);
}
void GetItemRect(short inItem, Rect *outRect)
{
DITLHand theDITL;
theDITL = (DITLHand) GetResource('DITL', ditl_about);
*outRect = (**theDITL).theUserItems[inItem - 1].box;
}
void DrawPictIntoNewGWorld(short inPICTid, short inDepth,
GWorldPtr *outGWorldP)
{
PicHandle thePicture;
Rect picFrame;
GWorldPtr saveWorld;
GDHandle saveDevice;
OSErr err;
thePicture = GetPicture(inPICTid);
picFrame = (**thePicture).picFrame;
err = NewGWorld(outGWorldP, inDepth, &picFrame, nil,
GetGWorldDevice(drawWorldP), noNewDevice);
GetGWorld(&saveWorld, &saveDevice);
SetGWorld (*outGWorldP, nil);
LockPixels(GetGWorldPixMap(*outGWorldP));
DrawPicture(thePicture, &picFrame);
UnlockPixels(GetGWorldPixMap(*outGWorldP));
SetGWorld(saveWorld, saveDevice);
ReleaseResource((Handle)thePicture);
}
void DrawTextIntoNewGWorld(short inTEXTid, Rect *ioBounds, short inDepth,
GWorldPtr *outGWorldP)
{
Handle theText;
TEHandle theTE;
StScrpHandle theStyle;
GWorldPtr saveWorld;
GDHandle saveDevice;
OSErr err;
// Put Text in a TERecord
TextFont(applFont);
TextSize(9);
theTE = TEStylNew(ioBounds, ioBounds);
theText = GetResource('TEXT', inTEXTid);
theStyle = (StScrpHandle) GetResource('styl', inTEXTid);
HLock(theText);
HidePen();
TEStylInsert(*theText, GetHandleSize(theText), theStyle, theTE);
ShowPen();
ReleaseResource(theText);
if (theStyle != nil) {
ReleaseResource((Handle)theStyle);
}
TESetJust(teJustRight, theTE);
TECalText(theTE);
// Determine height of the Text
ioBounds->right = ioBounds->right - ioBounds->left;
ioBounds->left = ioBounds->top = 0;
ioBounds->bottom = TEGetHeight((**theTE).nLines, 0, theTE);
// Create new GWorld that is the height of the Text
err = NewGWorld(outGWorldP, inDepth, ioBounds, nil,
GetGWorldDevice(drawWorldP), noNewDevice);
GetGWorld(&saveWorld, &saveDevice);
SetGWorld (*outGWorldP, nil);
LockPixels(GetGWorldPixMap(*outGWorldP));
EraseRect(ioBounds);
// Draw Text inside GWorld
(**theTE).viewRect = *ioBounds;
(**theTE).destRect = *ioBounds;
(**theTE).inPort = (GrafPtr) *outGWorldP;
TEUpdate(ioBounds, theTE);
TEDispose(theTE);
InvertRect(ioBounds); // White letters on black background
UnlockPixels(GetGWorldPixMap(*outGWorldP));
SetGWorld(saveWorld, saveDevice);
}